from appium import webdriver
import time
from selenium.webdriver.common.by import By

def getSize(driver):
    x=driver.get_window_size()['width']
    y=driver.get_window_size()['height']
    x1=x*0.75
    x2=x*0.25
    y1=x*0.75
    y2=x*0.25
    return x1,y1,x2,y2
def swipeUp(driver):
    x1,y1,x2,y2=getSize(driver)
    driver.swipe(x1,y1,x1,y2,1000)

def startUp():
    print('准备启动')
    # 启动参数
    desire_caps = {
        "deviceName":"127.0.0.1:21503",
        "platformName": "Android",
        "platformVersion": "5.1.1",
        "appPackage": "com.ss.android.article.news",
        "appActivity": "com.ss.android.article.news.activity.MainActivity",
        "noReset": True,
        "unicodeKeyboard": True
    }
    # 启动目标设备和app
    driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desire_caps)
    print('启动成功，等待 6s 关闭')
    time.sleep(6)
    swipeUp(driver)
    time.sleep(6)
    page = driver.page_source
    assert '打麻将' in page
    # # 定位输入框
    # driver.find_element(By.ID,'com.ss.android.article.news:id/bpb').click()
    # # 搜索目标元素
    # # driver.find_element(By.ID, 'com.ss.android.article.news:id/w3').send_keys('橙好测试开发')
    # driver.find_element(By.ID,'com.ss.android.article.news:id/w3').send_keys('橙好测试开发')
    # time.sleep(2)
    # driver.find_element(By.ID,'com.ss.android.article.news:id/acz').click()
    # # result=driver.find_element(By.ID,'com.ss.android.article.news:id/bea').text
    # # print(result)
    # driver.find_element(By.ID,'com.ss.android.article.news:id/title').get_attribute('text')
    # driver.tap([(200,265)])
    # driver.tap([(200,800)])
    # res=driver.get_window_size()
    # print(res)
    # res1=driver.current_package
    # print(res1)
    # res2=driver.current_activity
    # print(res2)

    # # 智能等待
    # driver.implicitly_wait(10)
    # # 等待时间，防止启动后立马关闭
    # time.sleep(4)
    # driver.quit()
    return driver
if __name__ == '__main__':
    startUp()